//#region 查询部门
let selSector = document.getElementById('selSector');

function querySector() {
  ajax.get('/link/departments', {}, (info) => {
    if (!info.success) {
      alert(info.message);
      return;
    }
    for (let i = 0; i < info.data.length; i++) {
      let bm = info.data[i];
      let op = document.createElement('option');
      op.setAttribute('value', bm.deptId);
      op.append(bm.deptName);
      selSector.append(op);
    }
  });
}

// querySector();

//#endregion

//#region 部门联动

let selWorker = document.getElementById('selWorker');

selSector.addEventListener('change', () => {
  // 清除原有数据
  selWorker.innerHTML = '';
  // 获取部门的值
  let deptId = selSector.value;
  if (deptId == -1) {
    return;
  }
  ajax.get(`/link/employees/${deptId}`, {}, (info) => {
    if (!info.success) {
      alert(info.message);
      return;
    }
    // 循环添加
    for (let i = 0; i < info.data.length; i++) {
      let yg = info.data[i];
      let op = document.createElement('option');
      op.setAttribute('value', yg.employeeId);
      op.append(yg.employeeName);
      selWorker.append(op);
    }
  });
});


querySector();

//#endregion

//#region 编号部分

let spSector = document.getElementById('spSector');
let spWorker = document.getElementById('spWorker');

selSector.addEventListener('change', () => {
  spSector.innerHTML = selSector.value;
});

selWorker.addEventListener('change', (info) => {
  spWorker.innerHTML = selWorker.value;
});

//#endregion
